package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Z.lx
 * @Date: 2025/7/31 21:16
 * @Description: 管理员订单管理
 **/

@RestController
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
    * @Description 取消订单
    * @Param [ordersCancelDTO]
    * @Date 2025/7/31 21:23
    **/
    @PutMapping("cancel")
    public Result<String> cancelOrder(OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单：{}", ordersCancelDTO);
        orderService.adminCancle(ordersCancelDTO);
        return Result.success();
    }

    /**
    * @Description 订单统计
    * @Param []
    * @Date 2025/7/31 21:23
    **/
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("订单统计");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
    * @Description 订单搜索
    * @Param [ordersPageQueryDTO]
    * @Date 2025/7/31 21:23
    **/
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索：{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.listOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
    * @Description 订单详情
    * @Param [id]
    * @Date 2025/7/31 21:23
    **/
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("订单详情：{}", id);
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    /**
    * @Description 订单派送
    * @Param [id]
    * @Date 2025/7/31 21:23
    **/
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id){
        log.info("订单派送：{}", id);
        orderService.delivery(id);
        return Result.success();
    }

    /**
    * @Description 接单
    * @Param [id]
    * @Date 2025/7/31 21:23
    **/
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单：{}", ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
    * @Description 拒单
    * @Param [ordersRejectionDTO]
    * @Date 2025/7/31 21:23
    **/
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        log.info("拒单：{}", ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
    * @Description 完成订单
    * @Param [id]
    * @Date 2025/7/31 21:23
    **/
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id){
        log.info("完成订单：{}", id);
        orderService.complete(id);
        return Result.success();
    }
}
